function [R,C,sens]=celdas_sedrahp(wp,qp,g,wz,seteaditos)
%setea(2): R4(GB) y C1(C3)

out=0;
coef=3;
while (~out)
    q0=qp/coef;
    K=1+(1-q0/qp)/(2*q0^2);
    k=g*(wz/wp)^2/(1-q0/qp);
    m=k*((K-1)/K)*(1+2*q0^2*(wp/wz)^2);
    n=k*(1-q0/(K*qp));
    if ~(k>0 && k<1 && m>0 && m<1 && n>0 && n<1)
        coef=coef+1;
        if coef>100
            out=1;
        end
    else
        out=1;
    end
end
C3=seteaditos(2);
C21=(1-m)*C3;
C22=m*C3;

G1=2*q0*wp*C3;
G41=(1-n)*G1/(4*q0^2);
G42=n*G1/(4*q0^2);

GB=1/(seteaditos(1));

GAprima=GB*(1/(2*q0^2)-wp*C3/(qp*G1));
GA2=k*GAprima;
GA1=(1-k)*GAprima;



R(1)=1/G1;
R(2)=1/G41;
R(3)=1/G42;
R(4)=1/GB;
R(5)=1/GA1;
R(6)=1/GA2;

C(1)=C3;
C(2)=C21;
C(3)=C22;

sens = [senWpSed(R,C);senQSed(R,C);senGSed(R,C);senWzSed(R,C)];
sens = sens';
end


function senWp = senWpSed(R,C)
senWp(1) = -0.5;
senWp(2) = -R(3)/(2*(R(2)+R(3)));
senWp(3) = -R(2)/(2*(R(2)+R(3)));
senWp(4) = 0;
senWp(5) = 0;
senWp(6) = 0;
senWp(7) = -0.5;
senWp(8) = -C(2)/(2*(C(2)+C(3)));
senWp(9) = -C(3)/(2*(C(2)+C(3)));
end

function senWz = senWzSed(R,C)
senWz(1) = -1/2;
senWz(2) = (R(5)*R(4)*R(3))/(2*R(5)*R(2)*R(6) + 2*R(4)*R(2)*R(6) - 2*R(5)*R(4)*R(3));
senWz(3) = -(R(2)*R(6)*(R(5) + R(4)))/(2*(R(5)*R(2)*R(6) + R(4)*R(2)*R(6) - R(5)*R(4)*R(3)));
senWz(4) = (R(5)^2*R(4)*R(6)*(C(2)*R(2) - C(3)*R(3)))/(2*(C(3)*R(5)*R(6) - C(2)*R(5)*R(4) + C(3)*R(4)*R(6))*(R(5)*R(2)*R(6) + R(4)*R(2)*R(6) - R(5)*R(4)*R(3)));
senWz(5) = (R(5)*R(4)^2*R(6)*(C(2)*R(2) - C(3)*R(3)))/(2*(C(3)*R(5)*R(6) - C(2)*R(5)*R(4) + C(3)*R(4)*R(6))*(R(5)*R(2)*R(6) + R(4)*R(2)*R(6) - R(5)*R(4)*R(3)));
senWz(6) = -(R(5)*R(4)*R(6)*(R(5) + R(4))*(C(2)*R(2) - C(3)*R(3)))/(2*(C(3)*R(5)*R(6) - C(2)*R(5)*R(4) + C(3)*R(4)*R(6))*(R(5)*R(2)*R(6) + R(4)*R(2)*R(6) - R(5)*R(4)*R(3)));


senWz(7) = -1/2;
senWz(8) =(C(2)*R(5)*R(4))/(2*C(3)*R(5)*R(6) - 2*C(2)*R(5)*R(4) + 2*C(3)*R(4)*R(6));
senWz(9) =-(C(3)*R(6)*(R(5) + R(4)))/(2*(C(3)*R(5)*R(6) - C(2)*R(5)*R(4) + C(3)*R(4)*R(6)));
%{
senWz(1) = -0.5;
senWz(2) = R(3)*R(5)*R(4)/(2*(R(2)*R(5)*R(6)+R(2)*R(6)*R(4)+R(3)*R(5)*R(4)));
senWz(3) = -R(2)*R(6)*(R(5)+R(4))/(2*(R(2)*R(5)*R(6)+R(2)*R(6)*R(4)+R(3)*R(5)*R(4)));
senWz(4) = 0;
senWz(5) = 0;
senWz(6) = 0;
senWz(7) = -0.5;
senWz(8) = -C(2)*R(5)*R(4)/(2*(C(3)*R(5)*R(6)-C(2)*R(5)*R(4)+C(3)*R(6)*R(4)));
senWz(9) = -C(3)*(R(5)+R(4))*R(6)/(2*(C(3)*R(5)*R(6)-C(2)*R(5)*R(4)+C(3)*R(6)*R(4)));
%}
end

function senG = senGSed(R,C)

senG(1) = 0;
senG(2) = 0;
senG(3) = 0;
senG(4)=-(R(4)*(C(2)*R(5) - C(3)*R(6)))/(C(3)*R(5)*R(6) - C(2)*R(5)*R(4) + C(3)*R(4)*R(6));
senG(5)=(C(3)*R(4)*R(6))/(R(5)*(C(2)*R(4) - C(3)*R(6)) - C(3)*R(4)*R(6));
senG(6)=(C(2)*R(5)*R(4))/(C(3)*R(5)*R(6) - C(2)*R(5)*R(4) + C(3)*R(4)*R(6));

senG(7)=0;
senG(8)=(C(2)*C(3)*R(4)*(1/R(5) + 1/R(4) + 1/R(6)))/((R(4)/R(6) - (C(3)*R(4)*(1/R(5) + 1/R(4) + 1/R(6)))/(C(2) + C(3)))*(C(2) + C(3))^2);
senG(9)=-(C(3)*((R(4)*(1/R(5) + 1/R(4) + 1/R(6)))/(C(2) + C(3)) - (C(3)*R(4)*(1/R(5) + 1/R(4) + 1/R(6)))/(C(2) + C(3))^2))/(R(4)/R(6) - (C(3)*R(4)*(1/R(5) + 1/R(4) + 1/R(6)))/(C(2) + C(3)));



%{
senG(1) = 0;
senG(2) = 0;
senG(3) = 0;
senG(4) = - (R(4)*(C(2)*R(5)-C(3)*R(6)))/(C(3)*R(5)*R(6)-C(2)*R(5)*R(4)+C(3)*R(6)*R(4));
senG(5) = - (R(4)*(C(3)*R(6)))/(C(3)*R(5)*R(6)-C(2)*R(5)*R(4)+C(3)*R(6)*R(4));
senG(6) = - (R(4)*(C(3)*R(5)))/(C(3)*R(5)*R(6)-C(2)*R(5)*R(4)+C(3)*R(6)*R(4));
senG(7) = 0;
senG(8) = C(2)*C(3)*R(4)*(1/R(5)+1/R(6)+1/R(4))/((C(2)+C(3))^2*(R(4)/R(6)-C(3)*R(4)*(1/R(5)+1/R(6)+1/R(4))/(C(2)+C(3))));
senG(9) = (1-C(3)/(C(2)+C(3)))/((C(2)+C(3))/(C(3)*R(6))*(1/(1/R(5)+1/R(6)+1/R(4)))-1);
%}
end

function senQ = senQSed(R,C)
senQ(1)=-(C(2)*R(5)*R(2)*R(6)*R(1) + C(1)*R(5)*R(4)*R(2)*R(3) + C(2)*R(5)*R(6)*R(3)*R(1) + C(3)*R(5)*R(2)*R(6)*R(1) + C(1)*R(4)*R(2)*R(6)*R(3) + C(1)*R(5)*R(2)*R(6)*R(1) + C(3)*R(5)*R(6)*R(3)*R(1) + C(1)*R(5)*R(6)*R(3)*R(1))/(2*(C(2)*R(5)*R(2)*R(6)*R(1) - C(1)*R(5)*R(4)*R(2)*R(3) + C(2)*R(5)*R(6)*R(3)*R(1) + C(3)*R(5)*R(2)*R(6)*R(1) - C(1)*R(4)*R(2)*R(6)*R(3) + C(1)*R(5)*R(2)*R(6)*R(1) + C(3)*R(5)*R(6)*R(3)*R(1) + C(1)*R(5)*R(6)*R(3)*R(1)));
senQ(2)=(R(2)*((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))))*(((1/(C(2) + C(3)) + 1/C(1))*((1/R(2) + 1/R(3))/(C(1)*R(1)*(C(2) + C(3))))^(1/2))/(R(2)^2*((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))))^2) - 1/(2*C(1)*R(2)^2*R(1)*((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))))*(C(2) + C(3))*((1/R(2) + 1/R(3))/(C(1)*R(1)*(C(2) + C(3))))^(1/2))))/((1/R(2) + 1/R(3))/(C(1)*R(1)*(C(2) + C(3))))^(1/2);
senQ(3)=(R(3)*((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))))*(((1/(C(2) + C(3)) + 1/C(1))*((1/R(2) + 1/R(3))/(C(1)*R(1)*(C(2) + C(3))))^(1/2))/(R(3)^2*((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))))^2) - 1/(2*C(1)*R(3)^2*R(1)*((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))))*(C(2) + C(3))*((1/R(2) + 1/R(3))/(C(1)*R(1)*(C(2) + C(3))))^(1/2))))/((1/R(2) + 1/R(3))/(C(1)*R(1)*(C(2) + C(3))))^(1/2);
senQ(4)=(R(4)*(1/R(5) + 1/R(6)))/(R(1)*((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))))*(C(2) + C(3)));
senQ(5)=-R(4)/(R(5)*R(1)*((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))))*(C(2) + C(3)));
senQ(6)=-R(4)/(R(6)*R(1)*((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))))*(C(2) + C(3)));

senQ(7)=(1/R(2) + 1/R(3))/(C(1)*((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))))) - (1/(2*R(2)) + 1/(2*R(3)))/(1/R(2) + 1/R(3));
senQ(8)=(C(2)*((1/R(2) + 1/R(3))/(C(2) + C(3))^2 - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))^2)))/((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3)))) - C(2)/(2*(C(2) + C(3)));
senQ(9)=(C(3)*((1/R(2) + 1/R(3))/(C(2) + C(3))^2 - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3))^2)))/((1/(C(2) + C(3)) + 1/C(1))*(1/R(2) + 1/R(3)) - (R(4)*(1/R(5) + 1/R(6)))/(R(1)*(C(2) + C(3)))) - C(3)/(2*(C(2) + C(3)));
%{
senQ(1) = -0.5-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3))*((2/R(2))*(1/(C(2)+C(3))+1/C(1))-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3)))));
senQ(2) = (1/(C(2)+C(3))+1/C(1))/(R(2)*((2/R(2))*(1/(C(2)+C(3))+1/C(1))-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3)))))-R(3)/(2*(R(2)+R(3)));
senQ(3) = (1/(C(2)+C(3))+1/C(1))/(R(3)*((2/R(2))*(1/(C(2)+C(3))+1/C(1))-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3)))))-R(2)/(2*(R(2)+R(3)));
senQ(4) = R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3))*((2/R(2))*(1/(C(2)+C(3))+1/C(1))-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3)))));
senQ(5) = - R(4)/((R(1)*R(5)*(C(2)+C(3))*((2/R(2))*(1/(C(2)+C(3))+1/C(1))-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3))))));
senQ(6) = - R(4)/((R(1)*R(6)*(C(2)+C(3))*((2/R(2))*(1/(C(2)+C(3))+1/C(1))-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3))))));
senQ(7) = -0.5+(1/R(2)+1/R(3))/(C(1)*((2/R(2))*(1/(C(2)+C(3))+1/C(1))-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3)))));
senQ(8) = C(2)*((2/R(2))/(C(2)+C(3))^2-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3))^2))/((2/R(2))*(1/(C(2)+C(3))+1/C(1))-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3)))) - C(2)/(2*(C(2)+C(3)));
senQ(9) = C(3)*((2/R(2))/(C(2)+C(3))^2-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3))^2))/((2/R(2))*(1/(C(2)+C(3))+1/C(1))-R(4)*(1/R(5)+1/R(6))/(R(1)*(C(2)+C(3)))) - C(3)/(2*(C(2)+C(3)));
%}
end